<template>
  <div class="day-task-slider">
    <h4 class="day-task-slider-title">{{ currentDay }} 巡检任务</h4>
    <px-scrollbar v-show="taskData[currentDay]?.length > 0">
      <ul>
        <li
          class="day-task-list-item"
          v-for="(item, index) in taskData[currentDay]"
          :key="`${item.id}${index}${currentDay}`"
          @mouseenter="currentTask = item"
          @mouseleave="currentTask = null"
          @click="handleClick(item)"
        >
          <div class="content">
            <px-text truncated class="taskName">{{ item.taskName }}</px-text>
            <p class="date-range">{{ item.startTime.replace(/-/g, "/") }}~{{ item.endTime.replace(/-/g, "/") }}</p>
          </div>
          <div class="status">
            <div class="circle" :style="{ backgroundColor: `${TAG_CONFIG[item.taskStatus]?.color}` }"></div>
            <p class="taskStatusDesc">{{ item.taskStatusDesc }}</p>
          </div>
        </li>
      </ul>
    </px-scrollbar>
    <div v-show="taskData[currentDay]?.length === 0">暂无数据</div>
  </div>
</template>
<script setup lang="ts">
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
// 根据后端巡检任务字典接口返回内容配置
const TAG_CONFIG = {
  0: {
    color: "#909399"
  }, // 已取消
  1: {
    color: "#F59E0B"
  }, // 未开始
  2: {
    color: "#3B82F6"
  }, // 执行中
  3: {
    color: "#10B981"
  }, // 已完成
  6: {
    color: "#FFC53D"
  }, // 待审核
  9: {
    color: "#EF4444"
  } // 撤回审核
};
const currentTask = defineModel("currentTask");
const props = defineProps(["currentDay", "taskData"]);
const handleClick = item => {
  router.push(`/erc/inspect/task?taskNo=${item.taskNo}`);
};
</script>
<style lang="scss">
.day-task-slider {
  width: 408px;
  flex-shrink: 0;
  height: 100%;
  padding: 28px 24px;
  background: #ffffff;
  border-radius: 4px;
  margin-left: 16px;
  &-title {
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    line-height: 22px;
    color: #000;

    &::before {
      display: inline-block;
      width: 3px;
      height: 16px;
      margin-right: 6px;
      vertical-align: middle;
      content: "";
      background: #3b82f6;
      border-radius: 0 100px 100px 0;
    }
  }
  .taskStatusDesc {
    height: 22px;
    font-size: 14px;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.8);
    line-height: 22px;
  }
  .content {
    max-width: 262px;
  }
  .date-range {
    height: 20px;
    font-size: 12px;
    font-weight: 400;
    color: #909399;
    line-height: 20px;
  }
  .taskName {
    max-width: 262px;
    height: 24px;
    font-size: 16px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.9);
    line-height: 24px;
  }
  .day-task-list-item {
    width: 360px;
    height: 68px;
    background: #ffffff;
    border-radius: 4px;
    border: 1px solid #dcdcdc;
    margin-bottom: 12px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    cursor: pointer;
    &:hover {
      background: #ecf5ff;
      .taskName {
        color: #3b82f6;
      }
    }
  }
  .status {
    display: flex;
    align-items: center;
  }
  .circle {
    width: 8px;
    height: 8px;
    margin-right: 5px;
    border-radius: 50%;
    flex-shrink: 0;
  }
}
</style>
